from django.shortcuts import render,HttpResponse
from library import models

# Create your views here.

def publisher(req):
    if req.method == "POST":
        name = req.POST.get("name", None)
        address = req.POST.get("address", None)
        city = req.POST.get("city", None)
        country = req.POST.get("country", None)
        website = req.POST.get("website", None)
        publisher_info = {"name": name, "address": address, "city": city, "country": country, "website": website}
        models.Publisher.objects.create(**publisher_info)
        info_list = models.Publisher.objects.all()
        return render(req, "publisher.html", {"info_list": info_list})
    info_list = models.Publisher.objects.all()
    return render(req, "publisher.html", {"info_list": info_list})


def author(req):
    # book = models.Book.objects.filter(id__gt=1)
    # authors = models.Author.objects.filter(id=1)[0]
    # authors.book_set.add(*book)
    #authors.book_set.remove(*book)
    obj_set=models.Publisher.objects.filter(id=1)[0]
    print(type(obj_set))
    obj_set1=models.Publisher.objects.filter(id=1)
    print(type(obj_set1))
    for i in obj_set1:
        print(i)
    # for i in obj:
    #     result = i.name
    # if obj_set.exists():
    #     result = "exists"
    # else:
    #     result = "not exists"
    return HttpResponse("result")

def book(req):
    pass

